<!--编辑库存-->
<div class="dialog_content">
	<form id="info_form" name="info_form" action="{:u('inventory/edit')}" method="post">
	<table width="100%" class="table_form">
		<tr> 
	      <th width="80">{:L('region_cate_name')} :</th>
	      <td>
                <select id="region_cate_edit" name="regionId">
                    <option value="0">{:L('please_select')}</option>
                    {$regionMenus}
                </select>          
          </td>
	    </tr>        
		<tr> 
	      <th width="80">{:L('store_name')} :</th>
	      <td>
                <select name="storeId" id="store_select_add">
                    <option value="0">{:L('please_select_region')}</option>                    
                </select>          
          </td>
	    </tr>	    
		<tr> 
	      <th width="80">{:L('brand_name')} :</th>
	      <td>
            <select name="brandId" id="brand_select_edit">
                <option value="0">{:L('please_select')}</option>
                <volist name="brandList" id="val">
                    <option value="{$key}" <if condition="$info.brandId eq $key">selected="true"</if>>{$val}</option>
                </volist> 
            </select>         
          </td>
	    </tr>   
             
		<tr> 
	      <th width="80">{:L('model_name')} :</th>
	      <td>
            <select name="modelId" id="model_select_add">
                <option value="0">{:L('please_select_brand')}</option>
                
            </select>         
          </td>
	    </tr> 
        
        <tr>
            <th width="80">{:L('customer_inventory')} :</th>
            <td><input type="text" class="input-text" value="{$info.customerInventory}" name="customerInventory" /></td>
        </tr>
        
	</table>
    <input type="hidden" name="id" value="{$info.id}" />
	</form>
</div>
<script>
$(function(){
	$.formValidator.initConfig({formid:"info_form",autotip:true});
	
	$("#store_select_add").formValidator({ onshow:lang.please_select+lang.store, onfocus:lang.please_select+lang.store}).inputValidator({ min:1, onerror:lang.please_select+lang.store,onsuccess:lang.select_right}).defaultPassed();
    
    $("#model_select_add").formValidator({ onshow:lang.please_select+lang.model, onfocus:lang.please_select+lang.model}).inputValidator({ min:1, onerror:lang.please_select+lang.model,onsuccess:lang.select_right}).defaultPassed();
    	
	$('#info_form').ajaxForm({success:complate,dataType:'json'});
    function complate(result){
        if(result.status == 1){
            $.dialog.get(result.dialog).close();
            $.pinphp.tip({content:result.msg});
            window.location.reload();
        } else {
            $.pinphp.tip({content:result.msg, icon:'alert'});
        }
    }
});

$(document).ready(function(){
    $("#region_cate_edit").change(function(){
       var _this = $(this);
       var region_id = _this.val();
       var ajax_get_region = "{:U('store/getStoreList')}";
       var store_id = "{$info.storeId}";
       if(region_id){
        $.ajax({
            url:ajax_get_region,
            data:"region_id="+region_id,
            dataType:"json",
            success:function(data){
                if(data.status==1){
                    var str = '<option value="0">'+lang.please_select+'</option>';
                    for(d in data.data){
                        var is_select = '';
                        if(d==store_id){
                            is_select = 'selected="true"';
                        }                        
                        str +='<option value="'+d+'"'+is_select+'>'+data['data'][d]+'</option>';
                    }
                    $("#store_select_add").html(str);
                }
            }
        });        
       }         
    });
    
    $("#brand_select_edit").change(function(){
       var _this = $(this);
       var brand_id = _this.val();
       var ajax_get_region = "{:U('model/getModelList')}";
       var model_id = "{$info.modelId}";
       if(brand_id){
        $.ajax({
            url:ajax_get_region,
            data:"brand_id="+brand_id,
            dataType:"json",
            success:function(data){
                if(data.status==1){
                    var str = '<option value="0">'+lang.please_select+'</option>';
                    for(d in data.data){
                        var is_select = '';
                        if(d==model_id){
                            is_select = 'selected="true"';
                        }                        
                        str +='<option value="'+d+'"'+is_select+'>'+data['data'][d]+'</option>';
                    }
                    $("#model_select_add").html(str);
                }
            }
        });        
       }                 
        
    });
    $("#region_cate_edit").change();
    $("#brand_select_edit").change();
});

</script>